<script>
import { getCurrentInstance, h, inject, nextTick, ref, watch } from 'vue';

export default {
    props: ['Plugin'],
    setup(props, { slots, expose }) {
        const { appContext } = getCurrentInstance();
        var _PluginComp = appContext.config.globalProperties.$PluginComp
        var isHave = props.Plugin in _PluginComp;
        const Comp = ref();
        expose({ Comp });
        const onLoad = inject(props.Plugin + '.load', () => { })
        watch(Comp, val => {
            setTimeout(() => {
                onLoad(val)
            }, 10)
        });

        return () => {
            if (isHave) {
                return h(_PluginComp[props.Plugin], { ref: Comp }, slots)
            } else {
                return undefined
            }
        }
    },
}

</script>
